package com.example.hellodemo.jump;

import android.content.ComponentName;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.hellodemo.R;

public class AAJumpActivity extends AppCompatActivity {
    private Button jumpBtn;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activtiy_a);

        Log.d("AAJumpActivity","---onCreate---");
        Log.d("AAJumpActivity", "taskId" + getTaskId() + ",  hash:" + hashCode());
        logtaskName();

        jumpBtn = findViewById(R.id.jump_a1);
        jumpBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 显示跳转1  --- 常用
                Intent intent1 = new Intent(AAJumpActivity.this,ABJumpActivity.class);
                //通过Bundle 传递数据
                Bundle  bundle = new Bundle();
                bundle.putString("name","haha");
                bundle.putInt("age",30);
                intent1.putExtras(bundle);
//                startActivity(intent1);
                startActivityForResult(intent1,0);

//                // 显示跳转2
//                Intent intent2 = new Intent();
//                intent2.setClass(AAJumpActivity.this,ABJumpActivity.class);
//                startActivity(intent2);

//                              // 显示跳转3
//                Intent intent3 = new Intent();
//                intent3.setClassName(AAJumpActivity.this,"com.example.hellodemo.jump.ABJumpActivity");
//                startActivity(intent3);

//                // 显示跳转
//                Intent intent4 = new Intent();
//                intent4.setComponent(new ComponentName(AAJumpActivity.this,"\"com.example.hellodemo.jump.ABJumpActivity\""));
//                startActivity(intent4);
//
//                //隐式跳转
//                Intent intent5 = new Intent();
//                intent5.setAction("com.test.ABJumpActivity");
//                startActivity(intent5);
            }
        });


    }
   // 用于下一级Activity数据回调
    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        Log.d("返回的数据：",data.getExtras().getString("title"));

    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("AAJumpActivity","---onNewIntent---");
        Log.d("AAJumpActivity", "taskId" + getTaskId() + ",  hash:" + hashCode());
        logtaskName();
    }

    private  void logtaskName(){
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.d("Activity",info.taskAffinity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
